<template>
  <div class="section-wrap safeDetails hiddenlc">
    <!-- <img v-if="info.identity==2 || info.identity==3" src="@/assets/imgs/add_pro_icon.png" class="add_btn" @click="$router.push({path:'./registerDanger',query:{planId:info.id}})"> -->
    <!-- <div v-if="info.identity==2 || info.identity==3" class="add_btn" @click="$router.push({path:'./needcheckregisterDanger',query:{id:info.id}})"></div> -->
    <!-- 头部 -->
    <div class="headerBox">
      <div class="header">
        <x-icon type="ios-arrow-left" size="" class="icon-white" @click="goBack"></x-icon>
        安全检查详情
      </div>
    </div>
    <div class="form-section" style="margin-top: 40px;">
      <div class="form-item form-item-style1">
        <div class="label-title">
          <label>检查编号</label>
        </div>
        <div class="input_div">
          <input type="text"
                 :disabled="isDisabled" v-model="info.checkNo">
        </div>
      </div>
      <div class="form-item form-item-style1">
        <div class="label-title">
          <label>被检查单位</label>
        </div>
        <div class="input_div">
          <input type="text"
                 v-model="info.projectName"
                 disabled>
        </div>
      </div>
      <div class="form-item form-item-style1">
        <div class="label-title">
          <label>检查类型</label>
        </div>
        <div class="input_div">
          <input type="text" v-model="info.checkType"
                 disabled>
        </div>
      </div>
      <div class="form-item form-item-style1">
        <div class="label-title">
          <label>检查时间</label>
        </div>
        <div class="input_div">
          <!-- <input type="text" v-model="info.checkDate.substring(0,10)"
                 disabled> -->
          <p v-if="info.checkDate">{{info.checkDate.substring(0,10)}}</p>
        </div>
      </div>
      <div  class="form-item form-item-style1">
          <div class="label-title">
              <label>整改责任人</label>
              <i v-if="!isentdistable" class="iconfont icon-required"></i>
          </div>
          <div v-if="!isentdistable" class="input_div" @click="getGroup(1)">
              <input type="text"
              placeholder="请选择"
               v-model="subData.zgZrrName">
              <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
          </div>
          <div v-else class="input_div">
            <p>{{hideninfo.zgZrrName}}</p>
          </div>
      </div>
      <div  class="form-item form-item-style1">
          <div class="label-title">
              <label>参与检查人</label>
              <!-- <i class="iconfont icon-required"></i> -->
          </div>
          <div  v-if="!isentdistable" class="input_div" @click="checkpersonValue=true">
              <input type="text"
              placeholder="请选择"
              :disabled="isentdistable" v-model="subData.PartakeCheckPerson">
              <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
          </div>
          <div v-else class="input_div">
            <p>{{hideninfo.partakeCheckPerson}}</p>
          </div>
      </div>
      <div  class="form-item form-item-style2">
          <div class="label-title">
              <label>被检查地点</label>
          </div>
          <div  v-if="!isentdistable">
              <textarea class="textarea" :max="500"  placeholder="请输入（可自动换行)"  maxlength="200" v-model="subData.CheckedPlaces"></textarea>
          </div>
          <div v-else class="input_div">
            <p>{{hideninfo.checkedPlaces}}</p>
          </div>
      </div>
      <div  class="form-item form-item-style2">
          <div class="label-title">
              <label>检查范围和内容</label>
          </div>
          <div v-if="!isentdistable">
              <textarea class="textarea" :max="500"  placeholder="请输入（可自动换行)"  maxlength="200" v-model="subData.CheckedRangeAndContent"></textarea>
          </div>
          <div v-else class="input_div">
            <p>{{hideninfo.checkedRangeAndContent}}</p>
          </div>
      </div>
      <div  class="form-item form-item-style1">
        <div class="label-title">
          <label>更多</label>
          <!-- <i class="iconfont icon-required"></i> -->
        </div>
        <div class="input_div" @click="addGoComm">
          <input type="text"
                disabled
                 v-model="zginfos"
          >
          <x-icon type="ios-arrow-right" size="22" class="icon-right" ></x-icon>
        </div>
      </div>
      <!-- <div class="form-item form-item-style1">
        <div class="label-title">
          <label>检查区域</label>
        </div>
        <div class="input_div">
          <input type="text" v-model="info.checkArea"
                 disabled>
        </div>
      </div>
      <div class="form-item form-item-style2">
        <div class="label-title">
          <label>检查内容</label>
        </div>
        <div>
          <p class="textarea">{{info.checkContent}}</p>
        </div>
      </div>
      <div class="form-item form-item-style2">
        <div class="label-title">
          <label>检查重点</label>
        </div>
        <div>
          <p class="textarea">{{info.checkPoint}}</p>
        </div>
      </div> -->

      <div class="info_div3" style="border-bottom: 1px solid #efeff4;">
        <p v-if="info.divisionList">检查组成员及分工<span>（{{info.divisionList.length}}条）</span></p>
        <p v-else>无检查组成员及分工</p>
        <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>

      </div>
      <div class="member_div">
        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>检查组长</label>
          </div>
          <div class="input_div">
            <input type="text" v-model="info.teamLeader"
                  disabled>
          </div>
        </div>
        <ul class="member_list">
          <li v-for="item in info.divisionList" :key="item.id">
            <div class="form-item form-item-style1">
              <div class="label-title">
                <label>成员：</label>
              </div>
              <div class="input_div">
                <input type="text" class="member1"
                       v-model="item.divisionProsonName"
                       disabled>
                       (
                         <span style="color:#469b7a;font-size:14px;" v-if="item.divisionIsSubmitted">已提交</span>
                         <span style="color:red;font-size:14px;" v-if="!item.divisionIsSubmitted">未提交</span>
                       )
              </div>
            </div>
            <div class="form-item form-item-style1" style="border-bottom: none;">
              <div class="label-title">
                <label>分工：</label>
              </div>
              <div class="input_div">
                <input type="text" v-model="item.standardNameList"
                       placeholder="请选择"
                       :disabled="isDisabled">
              </div>
            </div>
          </li>
        </ul>
      </div>
      <div class="notice_div" style="display:;">
        <div class="notice_top">
          <p v-if="info.divisionList">检查记录<span></span></p>
          <p v-else>无检查记录<span></span></p>
          <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
        </div>
        <ul class="notice_list">
          <li v-for="(name,index) in info.divisionList" :key="index">
            <div  class="down_div" v-if="((name.divisionProsonId==$store.state.userid) || (info.teamLeaderId==$store.state.userid&&name.divisionIsSubmitted)) && name.standardNameList!=null" @click="toggle(index)">
              <label>{{name.standardNameList}}</label>
              <div class="notice_item">
                <span v-if="name.contentList" class="notice_number">{{name.contentList.length}}</span>
                <x-icon type="ios-arrow-right" size="22" v-if="opensId.indexOf(index)==-1" ></x-icon>
                <x-icon type="ios-arrow-down" size="22" v-if="opensId.indexOf(index)>-1"></x-icon>
              </div>
            </div>
            <ul class="cList" :key="index" :class="[opensId.indexOf(index)?'active':'']">
              <li v-for="(val,index) in name.contentList" :key="index" @click="selectDivision(val.id)" class="clearfix">
                <p>{{val.checkContent}}</p>
                <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              </li>
            </ul>
          </li>
        </ul>
      </div>
      <!-- 问题记录 -->
      <div class="notice_div" style="display:">
        <div class="notice_top" >
          <p>发现问题<span>（{{totalcount}}条）</span></p>
          <!-- <x-icon type="ios-plus-outline" size="22" class="icon-down" @click="addGo"></x-icon> -->
        </div>
        <Slide :isdelete="true" @hiddenfun="hiddenfun"  :listArr="listArr"></Slide>
      </div>
      <div v-if="!isentdistable" class="form-item form-item-style1">
          <div class="label-title">
              <label>问题类别</label>
              <i class="iconfont icon-required"></i>
          </div>
          <div class="input_div" @click="questionValue=true">
              <input type="text"
                  placeholder="请选择"
                  disabled v-model="subData.hiddenDangerType">
              <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
          </div>
      </div>
      <div v-if="!isentdistable" class="form-item form-item-style2">
          <div class="label-title">
              <label>问题描述</label>
              <i class="iconfont icon-required"></i>
              <div class="input_div"  style="width:260px" @click="valueBtn3_2">
                  <input type="text"
                  placeholder="请选择"
                  disabled
                    style="float:right;margin-right:20px">
              </div>
          </div>
          <div @click="entdescription" >
              <textarea  class="textarea"  placeholder="请输入（可自动换行)"  maxlength="200" v-model="subData.hiddenDangeDescription"></textarea>
          </div>
      </div>
      <div v-if="!isentdistable" class="form-item form-item-style2">
              <div class="label-title space-between">
              <label>整改前图片<i class="iconfont icon-required"></i></label>
              <!-- <span>当前共{{detailinfo.projectImgList!=null?detailinfo.projectImgList.length:0}}张照片</span> -->
          </div>
          <div class="upload-wrap">
              <upload ref="child"
              :imgList="projectImgList1.rectifyImgList"
              @setFormData="setYSFormData"
              ></upload>
          </div>
      </div>
      <div v-if="!isentdistable" class="form-item form-item-style2">
          <div class="label-title">
              <label>整改要求</label>
              <i class="iconfont icon-required"></i>
          </div>
          <div @click="amend4">
              <textarea class="textarea" placeholder="请输入（可自动换行）" v-model="subData.measure"></textarea>
          </div>
      </div>
      <div v-if="!isentdistable" class="form-item form-item-style1">
          <div class="label-title">
              <label>整改期限</label>
              <i class="iconfont icon-required"></i>
          </div>
          <group>
              <datetime placeholder="请选择" :max="500" format="YYYY-MM-DD" v-model="subData.zgEndTime"></datetime>
          </group>
      </div>
      <div v-if="!isentdistable" class="btns">
          <p class="transfer_p"><span style="width:171px" @click="handleSubmit()">继续添加整改问题</span> </p>
      </div>
      <div class="info_div3"  v-if="(info.identity==1 || info.identity==3)&&isallsubmit">
        <p>生成通知单<span></span></p>
        <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
      </div>
      <div class="member_div" v-if="(info.identity==1 || info.identity==3)&&isallsubmit" >
        <ul class="member_list" id="safeDet">
          <li @click="routerGo('生成电网工程建设安全稽查整改通知单','1')">
            <div class="form-item form-item-style1" style="border-bottom: none;">
              <div>
                <label style="display: block;">生成电网工程建设安全稽查整改通知单</label>
              </div>
              <x-icon style="margin-top:-16px;margin-right:20px;" type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              <!-- <div class="input_div">
                <input type="text"
                       readonly>
                <x-icon style="margin-top:-16px;margin-right:20px;" type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              </div> -->
            </div>
              <div>
              <flow v-if="totalcount>0&&zgcount==0">
                <flow-state state="1" title="已登记问题" is-done></flow-state>
                <flow-line tip="未选择"></flow-line>
                <flow-state state="2" title="已选择"></flow-state>
              </flow>
              <flow v-if="totalcount>0&&zgcount>0">
                <flow-state state="1" title="已登记问题" is-done></flow-state>
                <flow-line is-done></flow-line>
                <flow-state state="2" title="已选择" is-done></flow-state> 
              </flow>
              <flow  v-if="totalcount==0">
                <flow-state state="1" title="未登记问题" is-done></flow-state>
                <flow-line></flow-line>
                <flow-state state="2" title="已选择"></flow-state>
              </flow>
              </div>
          </li>
          <li @click="routerGo('生成安全检查违章记分通知书','2')">
            <div class="form-item form-item-style1" style="border-bottom: none;">
              <div >
                <label style="display: block;">生成安全检查违章记分通知书</label>
              </div>
              <x-icon style="margin-top:-16px;margin-right:20px;" type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              <!-- <div class="input_div">
                <input type="text"
                       readonly>
                <x-icon style="margin-top:-16px;margin-right:20px;" type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              </div> -->
            </div>
              <div>
              <flow v-if="totalcount>0&&xfcount==0">
                <flow-state state="1" title="已登记问题" is-done></flow-state>
                <flow-line tip="未选择"></flow-line>
                <flow-state state="2" title="已选择"></flow-state>
              </flow>
              <flow v-if="totalcount>0&&xfcount>0">
                <flow-state state="1" title="已登记问题" is-done></flow-state>
                <flow-line is-done></flow-line>
                <flow-state state="2" title="已选择" is-done></flow-state> 
              </flow>
              <flow  v-if="totalcount==0">
                <flow-state state="1" title="未登记问题" is-done></flow-state>
                <flow-line></flow-line>
                <flow-state state="2" title="已选择"></flow-state>
              </flow>
              </div>
          </li>
          <!-- <li @click="notice(2)">
            <div class="form-item form-item-style1" style="border-bottom: none;">
              <div class="label-title">
                <label style="display: block;width: 150px;">设备停用通知单</label>
              </div>
              <div class="input_div">
                <input type="text"
                       readonly>
                <x-icon style="margin-top:-16px;margin-right:20px;" type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              </div>
            </div>
          </li>
          <li @click="notice(3)">
            <div class="form-item form-item-style1" style="border-bottom: none;">
              <div class="label-title">
                <label style="display: block;width: 150px;">停工通知单</label>
              </div>
              <div class="input_div">
                <input type="text"
                       readonly>
                <x-icon style="margin-top:-16px;margin-right:20px;" type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              </div>
            </div>
          </li> -->
        </ul>
      </div>
    </div>
    <div v-transfer-dom>
      <popup v-model="classValue4" width="100%" height="300px">
        <group>
          <x-textarea :max="200" name="description" placeholder="请输入内容" v-model="checkResult" id="tt"></x-textarea>
        </group>
        <p class="transfer_p"><span @click="addContent">确定</span><em  @click="checkResult=''">清空</em></p>
      </popup>
      <popup v-model="classValue" width="100%" height="100%" style="background: #fff">
        <div class="headerBox">
          <div class="header">
            <x-icon type="ios-arrow-left" size="" class="icon-white" @click="classValue=false"></x-icon>
            通知单
          </div>
        </div>
        <div style="background: white;margin-top: 50px">
          <el-tree
            v-if="classValue"
            :data="noticeList"
            show-checkbox
            node-key="id"
            :default-checked-keys='ids'
            ref="tree"
            :props="def"
          ></el-tree>
          <div style="text-align:  center;margin-top: 10px;padding-bottom: 5px">
            <el-button size="mini" @click="classValue=false">取消</el-button>
            <el-button size="mini" @click="clickClose">确认</el-button>
          </div>
        </div>
           </popup>
    </div>
    <div class="btns_div">
      <a class="submitBtn"  @click="confirmsubmit">提 交</a>
    </div>
      <!-- 问题类别 -->
      <popup v-model="questionValue" width="100%">
          <div id="classValue2">
              <!-- <group>
                  <radio :options="radio002" @on-change="change2"></radio>
              </group> -->
              <ul class="popList">
                  <li style="display: block;" :class="ind3==index ? 'active' : ''" v-for="(item,index) in radiolist" :key="index" @click="change2(item,index)">
                      <p>{{item}}<img src="../../../static/images/list_checked.png"></p>
                  </li>
              </ul>
          </div>
      </popup>
      <!-- 问题描述 -->
      <popup v-model="classValue3_2" width="100%">
          <div class="divClass" id="classValue2">
              <ul class="hiddden">
                  <li  :class="ind4==index ? 'active' : ''" v-for="(item,index) in radio003" :key="index" @click="change3(item,index)">
                      <p>{{item}}</p>
                      <img src="../../../static/images/list_checked.png">
                  </li>
              </ul>
          </div>
      </popup>
      <popup v-model="classValue11" width="100%" height="300px">
          <group>
                  <x-textarea :max="200" :rows="7" name="description" placeholder="请输入" v-model="checkData11" id="tt"></x-textarea>
          </group>
          <p class="transfer_p"><span @click="ent11">确定</span> <em @click="clear11">清空</em></p>
      </popup>
      <!-- 整改责任人 -->
      <popup v-model="classValue5" width="100%" >
          <select-depart :data="data2" @selectUser='selectUser'></select-depart>
      </popup>
      <!-- 参与检查人 -->
      <popup v-model="checkpersonValue" width="100%" height="60%" style="padding-bottom:40px;">
        <div style="background: white;height:100%;overflow-y:scroll;padding-bottom:20px;">
          <el-tree
            v-if="checkpersonValue"
            :data="data"
            node-key="id"
            :render-content="renderContent"
            :expand-on-click-node="true"
            ref="tree1"
            :props="defs"
          ></el-tree>
          <div style="text-align:  center;margin-top: 10px;padding-bottom: 5px;position: absolute;width: 100%;bottom: 15px;background-color: #eee;z-index: 10;">
            <el-button size="mini" @click="checkpersonValue=false">取消</el-button>
            <el-button size="mini"  @click="addUser">确认</el-button>
          </div>
        </div>
      </popup>
    <el-dialog   :visible.sync="isshow"   width="90%" center>
      <div  class="form-item form-item-style1">
          <div class="label-title">
              <label>问题类别</label>
          </div>
          <div class="input_div" >
               <p>{{datainfo.hiddenDangerType}}</p>
          </div>
      </div>
      <div  class="form-item form-item-style2">
          <div class="label-title">
              <label>问题描述</label>
          </div>
          <div class="input_div">
              <span>{{datainfo.hiddenDangeDescription}}</span>
          </div>
      </div>
      <div  class="form-item form-item-style2">
        <div class="label-title space-between">
          <div class="space-between">
            <label>整改前图片</label>
          </div>
          <span>当前共{{datainfo.projectImgList != null ? datainfo.projectImgList.length: 0}}张照片</span>
        </div>
        <div>
          <div class="upload-wrap"
          >
            <div class="upload-item"
                 v-for="(item,index) in datainfo.projectImgList"
                 :key="index">
              <img :src="item.url"
                   @click="previewImg(item.url)"
                   alt="">
            </div>
          </div>
        </div>
      </div>
      <div  class="form-item form-item-style2">
          <div class="label-title">
              <label>整改要求</label>
          </div>
          <div class="input_div">
              <span>{{datainfo.measure}}</span>
          </div>
      </div>
      <div class="form-item form-item-style1">
          <div class="label-title">
              <label>整改期限</label>
          </div>
          <div class="input_div">
             <p>{{datainfo.zgEndTime}}</p>
          </div>
      </div>
    </el-dialog>
    <div v-transfer-dom>
      <confirm v-model="isconfirm"
      title="是否添加问题？"
      confirm-text="是"
      cancel-text="否"
      @on-cancel="submitRecord"
      @on-confirm="tolsave">
      </confirm>
    </div>
  </div>
</template>
<script>
  import Slide from './slide';
  import CellBox from './cell';
  import ztree from "@commonComponents/tree"
  import upload from "@/commonComponents/upload/upload";
  import selectDepart from "@commonComponents/selectDepartUser/selectUser";
  import formatDate from "../../utils/formatDate";
  import {Flow, FlowState, FlowLine,XHeader, Tabbar, TabbarItem, Group,Confirm, Cell,TransferDomDirective as TransferDom, Popup} from 'vux';

  export default {
    data() {
      return {
        hideninfo:[],
        isentdistable:false,
        isconfirm:false,
        isok:false,
        isshow:false,
        zginfos:'安全稽查整改基本信息',
        isallsubmit:false,
        showContent002: false,
        arrList2:[],
        projectImgList1:[],
        data2: [],
        listArr:[],
        ind3:9999,
        ind4:9999,
        list:[],
        opensId:[],
        totalcount:'',
        type:"",
        noticesIds:[],
        noticesIds2:[],
        noticesIds3:[],
        def:{
          children:'data',
          label:"hiddenDangeDescription",
        },
        subData:{
            type:'dj',
            checkworkId:''
        },
        noticeList:[],
        ids:[],
        classValue: false,
        classValue2: false,
        classValue3: false,
        classValue4: false,
        classValue5: false,
        questionValue:false,
        classValue3_2:false,
        checkData11:'',
        classValue11:false,
        radiolist:[],
        radio003:[],
        checkResult:'',
        id:'',
        planId:'',
        classValue4:false,
        isDisabled: true, // 是否禁止输入
        datainfo:{},
        flag: false,
        selectImg: '',
        info:[],
        checkpersonValue:false,
        data: [],
        defs: {
          children: 'children',
          label: "departName"
        },
        itemId:'',
        peosonlist:[],
        xfcount:0,
        zgcount:0,
      }
    },
    components: {
      ztree, Popup,Slide,CellBox,upload,selectDepart,Confirm,Flow,FlowState,FlowLine
    },
    directives: {
      TransferDom
    },
    activated () {
       this.gethiddenNoticeList()
    },
    created() {
      if(JSON.stringify(this.$store.state.xfinfo) != "{}" && JSON.stringify(this.$store.state.xfinfo) !="null") {
        this.subData = this.$store.state.xfinfo
      }
      this.getInfo()
      this.gethiddenNoticeList()
      this.getPlanList()
      this.change0()
      this.examinedUnits()
      // 获取整改责任人员接口
      this.$axiosAjax.getDivision({classifyId: ''}).then((res) => {
          if (res.data.success == true) {
              this.data2 = res.data.result
          }
      }).catch((err) => {
          console.log(err)
          }
      )
      this.$axiosAjax.getHiddenInfo({}).then((res) => {
          if (res.data.success == true) {
              this.subData.checkDeptName=res.data.result.checkDeptName // 检查单位
              this.subData.checkDeptId=res.data.result.checkDeptId // 检查单位id
              this.subData.checkPerson=res.data.result.checkPerson // 检查人
              this.subData.telephone=res.data.result.telephone // 电话
              this.subData.checkTime=res.data.result.checkTime // 检查时间
              this.subData.parentDeptName=res.data.result.parentDeptName // 所属上级单位
              this.subData.parentDeptId=res.data.result.parentDeptId // 所属上级单位
          }
      }).catch((err) => {
          console.log(err)
          }
      )
    },
    methods: {
      // 被检查单位
      examinedUnits() {
        this.$axiosAjax.examinedUnits({parentId: this.$store.state.departId}).then((res) => {
          if (res.data.success == true) {
            this.data = res.data.result
          }
        }).catch((err) => {
          console.log(err)
          }
        )
      },
      // 参与检查人
      append (data) {
        if (!data.children) {
          this.$set(data, 'children', [])
        }
        var a =this.peosonlist
        if(a.length>0){
          a.forEach((item,i)=>{
            data.children.unshift({ id: item.id, departName: item.userName,type:"0", children: [] })
          })
        }
      },
      renderContent (h, { node, data, store }) {
        if(data.type=='0'){
          return (
            <span class="span">
            <span>
            <span class="ll" on-click={ () => this.nodeClicks(data) }>
            <el-checkbox on-change={ () => this.test(data) }>{node.label}</el-checkbox></span>
        </span>
          </span>
        )

        }else{
          return (
            <span class="span">
            <span>
            <span on-click={ () => this.nodeClicks(data) }>{node.label}
        </span>
          </span>
          </span>
        )
        }
      },
      test(data){
        if(this.ids.indexOf(data)==-1){
          this.ids.push(data)
        }else{
          this.ids.splice(data,1)
        }
      },
      addUser(){
        this.checkpersonValue=false
        if(this.ids.length>0){
          // this.params.receiverId = this.ids.map(x => x.id).join(',');
          this.subData.PartakeCheckPerson = this.ids.map(x => x.departName).join(',');
        }
      },
      nodeClicks(item) {
        if(this.itemId==item.id){
          return;
        }
        if(item.type=='0'){
          return;
        }
        this.itemId=item.id
        this.$axiosAjax.getUserList({departId:item.id}).then((res) => {
          if(res.data.success==true){
            if(res.data.result.totalCount>0){
              console.log(res.data.result)
              this.peosonlist = res.data.result.items;
              this.append (item)
            }
          }
        }).catch(
          (err)=>{

          }
        )
      },
      confirmsubmit () {
         //判断是否添加过隐患  如果没有则弹出提示框

         if(!this.isok || !this.$store.state.xfisok) {
           this.isconfirm=true
         } else {
           this.submitRecord()
         }
      },
      previewImg(url){//图片预览
        this.selectImg=url
        this.flag=true
      },
      hiddenfun (data) {
        this.isshow = true
        this.datainfo = data
        //更新公共部分数据
        this.hideninfo = data
        this.datainfo.zgEndTime = this.datainfo.zgEndTime.substring(0,10)
        // this.showContent002 = !this.showContent002
      },
      // 点击生成通知单
      routerGo(nam,type){
        //跳转前 保证当前页面
        this.$store.state.xfinfo = this.subData
        //跳转钱  保存当前状态isok
        this.$store.state.xfisok =this.isok
        this.$router.push({path:'./safeNotice',query:{name:name,type:type,id:this.$route.query.planId}})
      },
      // 问题记录
      getPlanList() {
        var p={
            skipCount:0,
            maxResultCount:10000,
            checkworkId:this.$route.query.planId
        }
        this.$axiosAjax.getHiddenPageList(p).then((res) => {
          if (res.data.success == true) {
            var list =res.data.result.items
            for (var k of list){
              if (k.projectImgList.length>0){
                k.imgUrl=k.projectImgList[0].url
              }  else {
                k.imgUrl=''
              }
            }
            this.$nextTick(() =>{ this.totalcount=list.length })
            this.listArr=list
            if(this.listArr.length>0) {
              this.isok = true
              this.$store.state.xfisok =this.isok
            }
          }
        }).catch((err) => {
          console.log(err)
          }
        )
        //同时判断是否 有选择下发内容
        if(this.$store.state.addCheckRecord.noticesIds2!=null) {
          this.xfcount = this.$store.state.addCheckRecord.noticesIds2.length
        }
        if(this.$store.state.addCheckRecord.noticesIds!=null) {
          this.zgcount = this.$store.state.addCheckRecord.noticesIds.length
        }
      },
        entdescription () {
           this.subData.measure = '及时整改'
        },
        //当选择新增问题 则提交两个
        tolsave() {
          this.handleSubmit(true)
        },
        // 提交
        handleSubmit (ishidden) {
            this.subData.hiddenDangerLevel = "一般问题"
            this.subData.projectType = '00000000-0000-0000-0000-000000000000'
            this.subData.bcheckDeptName = this.info.projectName
            this.subData.bcheckDeptId= this.info.projectId    // 参建单位ID
            this.subData.bcheckDeptFzr=this.info.charge      // 被检查单位负责人
            this.subData.zgStartTime = this.info.checkDate;
            this.subData.checkworkId=this.$route.query.planId
            if(this.subData.bcheckDeptName&&
                this.subData.hiddenDangerType&&
                this.subData.hiddenDangeDescription&&
                this.subData.measure&&
                this.subData.zgStartTime&&
                this.subData.zgEndTime&&
                this.subData.zgZrrName&&
                this.subData.fileList&&
                this.subData.fileList.length != 0
            ){
              this.subData.zgEndTime = this.subData.zgEndTime + " 00:00:00";
              this.$axiosAjax.submitHiddenDangerInfoAPP(this.subData).then((res) => {
                    if (res.data.success == true) {
                        if(ishidden) {
                          this.submitRecord()
                        } else {
                          this.isok = true
                          this.$vux.toast.text('提交成功')
                        }
                        //清空
                        this.subData.hiddenDangerType = ''
                        this.subData.hiddenDangeDescription = ''
                        this.subData.measure= ''
                        this.subData.zgEndTime = ''
                        this.subData.fileList = []
                        this.projectImgList1.rectifyImgList = []
                        this.$refs.child.clearimage() //清空子组件附件集合
                        this.getPlanList() // 刷新问题记录
                    }
                }).catch((err) => {
                    console.log(err)
                    }
                )
            } else if(!this.subData.bcheckDeptName){
                this.$vux.toast.text('被检查单位不能为空')
            }else if(!this.subData.hiddenDangerType){
                this.$vux.toast.text('问题类别不能为空')
            }else if(!this.subData.hiddenDangeDescription){
                this.$vux.toast.text('问题描述必填')
            }else if(!this.subData.measure){
                this.$vux.toast.text('整改要求必填')
            }else if(!this.subData.zgStartTime){
                this.$vux.toast.text('检查时间不能为空')
            }else if(!this.subData.zgEndTime){
                this.$vux.toast.text('整改期限不能为空')
            }else if(!this.subData.zgZrrName){
                this.$vux.toast.text('整改责任人必填')
            }else if(!this.subData.fileList || this.subData.fileList.length == 0){
                this.$vux.toast.text('整改前图片必传')
            }
        },
        // 获取人员数据
        getGroup (index) {
            this.groupIndex=index
            this.classValue5 = true;
        },
        // 人员选择
        selectUser(data) {
            if (this.groupIndex==1){  // 整改责任人
                this.subData.zgZrrName=data.userName
                this.subData.zgZrrId=data.userAccount
            } else if (this.groupIndex==2){  // 参与检查人
                this.subData.PartakeCheckPerson=data.userName
                // this.subData.copytoPersonId=data.id
            }
            this.classValue5 = false
        },
        valueBtn3_2(){
            if(this.subData.hiddenDangerType){
                this.classValue3_2=true
            }else if(!this.subData.hiddenDangerType){
                this.$vux.toast.text('先选择问题类别')
            }
        },
        amend4(){
            this.classValue11=true
            this.checkData11=this.subData.measure
        },
        ent11 (){
            this.classValue11=false
            this.subData.measure=this.checkData11
        },
        clear11(){
            this.classValue11=false
        },
        setYSFormData (setFormDatalength, file) {
            console.log(setFormDatalength, file,121)
            // this.YSFormData = formData;
            var arr =[]
            for (var k of file){
                arr.push(k.id)
            }
            this.subData.fileList=arr
        },
        //初始加载 根据项目类型获取问题类别
        change0 (value, index) {
            this.$axiosAjax.getHiddenDangerStatus2({hiddrenTypeId:'00000000-0000-0000-0000-000000000000'}).then((res) => {
                if (res.data.success == true) {
                    var list =res.data.result
                    this.arrList2=list
                    var arr=[]
                    for(var k of list){
                        arr.push(k.type)
                    }
                    this.radiolist=arr
                }
            }).catch((err) => {
                console.log(err)
                }
            )
        },
        // 问题类别
        change2 (value, index) {
            this.ind3=index
            this.subData.hiddenDangerType=value
            this.questionValue=false
            var id=''
            for (var k of this.arrList2){
                if (k.type==value){
                    id=k.id
                }
            }
            this.$axiosAjax.getStandard({parentId:id}).then((res) => {
                if (res.data.success == true) {
                    var list =res.data.result.items
                    this.arrList3=list
                    var arr=[]
                    for(var k of list){
                        arr.push(k.checkStandard)
                    }
                    console.log(this.radiolist)
                    this.radio003=arr
                    //同时清空 问题描述和措施
                     this.subData.hiddenDangeDescription=''
                     this.subData.measure=''
                }
            }).catch((err) => {
                console.log(err)
                }
            )
        },
        change3 (value, label) {
            this.ind4 = label
            this.subData.hiddenDangeDescription=value
            this.classValue3_2=false
            this.subData.hiddenDangeDescription=value
            for(var k of this.arrList3){
                if (k.checkStandard==value){
                    this.subData.measure=k.resolveMeasure
                }
            }
            this.classValue3_2=false
        },
      addGoComm(){
        //跳转前 保证当前页面
        this.$store.state.xfinfo = this.subData
        //跳转钱  保存当前状态isok
        this.$store.state.xfisok =this.isok
        this.$router.push({path:'./registerDangerNew',query:{id:this.$route.query.planId}})
        // if (this.$store.state.addCheckRecord.projectName){
        //   this.$router.push({path:'./registerDangerNew',query:{id:this.$route.query.id}})
        // }else {
        //   this.$vux.toast.text('先选择被检查单位')
        // }
      },
      init () {
        this.list = []
        this.getInfo()
        this.gethiddenNoticeList()
      },
      goBack() {
        this.$store.state.xfinfo=null
        this.$router.go(-1)
      },
      selectDivision(val){
        
        this.id=val;
        this.classValue4=true;
        this.checkResult=''
        this.list.forEach(item=>{
          if(item.id==val){
            this.checkResult=item.checkResult
          }
        })
      },
      clickClose(){
        this.classValue=false;
        var num=this.type
        var list=this.$refs.tree.getCheckedNodes()
        let i = [];
        list.forEach(item => {
          if(item.data==null){
            i.push(item.id);
          }
        })
        if(num==1){
          this.noticesIds=i
        }else if(num==2){
          this.noticesIds2=i
        }else{
          this.noticesIds3= i
        }
      },
      goBack() {
        this.$router.go(-1)
      },
      addContent(){
        // 修改原数组的数据
        this.classValue4=false;
        this.list.forEach(item=>{
          if(item.id==this.id){
            item.checkResult = this.checkResult
          }
        })
      },
      submitRecord(){
        var planId=this.planId
        var resultList=this.list
        let obj = {}
        obj['1'] = this.noticesIds
        obj['2'] = this.noticesIds2
        obj['3'] = this.noticesIds3
        //当为新增检查计划 同时没有检查内容 则组长可操作记录和登记问题下发
        if(this.info.isPlan==1 && this.info.divisionList==null)
        {
          this.isentdistable = false
        } else {
          let resultInput = this.list.some(item => {
            console.log('检查结果')
            console.log(item.checkResult)
            return !item.checkResult || item.checkResult=='' || (item.checkResult&&!item.checkResult.trim())
          })
          if(resultList==null ||resultList.length==0||resultInput){
            this.$vux.toast.text("请填写检查结果")
            return ;
          }
          // 用户为检查组长时，需提示填写检查记录(identity:1组长；2成员；3组长和成员)
          if (this.info.identity == 1 || this.info.identity == 3) {
            // 过滤出检查组长的检查记录项
            let leaderList = []
            this.list.forEach(item => {
              if (item.divisionProsonId == this.$store.state.userid) {
                leaderList.push(item)
              }
            })
            // 检查记录表,组长提示须填写检查结果
            let jcCheckResult = leaderList.every(item => {
              return !!item.checkResult;
            })
            if (!jcCheckResult) {
              this.$vux.toast.text("请填写检查结果")
              return false;
            }
          }
        }

        var parma={plandId:planId,resultList:resultList}
        parma.noticeData={
          '1':this.$store.state.addCheckRecord.noticesIds,
          '2':this.$store.state.addCheckRecord.noticesIds2,
          '3':this.$store.state.addCheckRecord.noticesIds3,
          '4':this.$store.state.addCheckRecord.noticesIds4
        }
        //获取选择的违章通通知书的 违章标准和抄送单位
        parma.IllegalSandardId = this.$store.state.addCheckRecord.IllegalSandardId
        parma.IllegalSandardName = this.$store.state.addCheckRecord.IllegalSandardName
        parma.PushDeptId = this.$store.state.addCheckRecord.PushDeptId
        parma.PushDeptName = this.$store.state.addCheckRecord.PushDeptName
        parma.checkClassName=this.$store.state.addCheckRecord.receivrtName
        parma.checkClassId=this.$store.state.addCheckRecord.checkClassId
        // return false
        this.$axiosAjax.safeCheckResult(parma).then(res => {
          if(res.data.success==true){
            this.$vux.toast.text("提交成功")
            this.$store.state.xfinfo=null
            this.$store.state.xfisok = false
            setTimeout(() => {
              this.goBack()
            }, 1000)
          }
        });
      },
      toggle(val){
        if(this.opensId.indexOf(val) > -1){
          this.opensId=[]
        }else{
          this.opensId=[]
          this.opensId.push(val)
        }
       /* if(this.opensId.indexOf(val) > -1){
          var index = this.opensId.findIndex(item =>{
            if(item=val){
              return true
            }
          })
          this.opensId.splice(index,1)
        }else{
          this.opensId.push(val)
        }*/
      },
      notice(num){
        if(this.noticeList.length==0){
          this.$vux.toast.text("没有登记的问题")
          return;
        }
        this.ids=[]
        if(num==1){
          this.ids=this.noticesIds
          this.$forceUpdate()
        }else if(num==2){
          this.ids=this.noticesIds2
          this.$forceUpdate()
        }else{
          this.ids=this.noticesIds3
          this.$forceUpdate()
        }
        this.classValue=true
        this.type=num

      },
      gethiddenNoticeList(){
        this.$axiosAjax.gethiddenNoticeList({planId:this.$route.query.planId}).then(res => {
          if(res.data.success==true){
            var arr=res.data.result
            if(arr.length>0) {
            this.hideninfo = res.data.result[0]
            var map = {},
              dest = [];
            for(var i = 0; i < arr.length; i++){
              var ai = arr[i];
              if(!map[ai.hiddenDangerType]){
                dest.push({
                  id: ai.id,
                  hiddenDangeDescription: ai.hiddenDangerType,
                  data: [ai]
                });
                map[ai.hiddenDangerType] = ai
              }else{
                for(var j = 0; j < dest.length; j++){
                  var dj = dest[j];
                  if(dj.hiddenDangeDescription == ai.hiddenDangerType){
                    dj.data.push(ai);
                    break;
                  }
                }
              }
            }
            console.log(dest)
            this.noticeList=dest
          }
          }
        });
      },
      getInfo(){
        this.$axiosAjax.getSafeDetails({planId:this.$route.query.planId}).then(res => {
          if(res.data.success==true){
            this.info=res.data.result
            if(this.info.identity==2 || this.info.identity==3) {
              this.isentdistable = false
            }else if(this.info.isPlan==1 && this.info.divisionList==null){
              //当为新增检查计划 同时没有检查内容 则组长可操作记录和登记问题下发
              this.isentdistable = false
              //同时 设置生成通知单 
              this.isallsubmit = true
            } else {
              this.isentdistable = true
              //同时设置 组长不弹是否添加问题框
              this.isok = true
            }

            this.$store.state.addCheck.charge=this.info.charge
            this.$store.state.addCheck.id=this.info.checkDeptId
            this.planId=res.data.result.id
            // 页面初始化添加检查记录表
            if (this.info.divisionList && this.info.divisionList.length > 0) {
              this.info.divisionList.forEach(divItem => {
                if(divItem.divisionIsSubmitted) {
                  this.isallsubmit = true
                } else {
                  this.isallsubmit = false
                }
                
               // if (divItem.divisionProsonId == this.$store.state.userid) {
                  divItem.contentList.forEach(item => {
                    this.list.push({
                      id: item.id,
                      checkResult: item.checkResult
                    })
                  })
              //  }
              })
            }

            if(!this.isallsubmit) {
              this.list = []
              
              if (this.info.divisionList && this.info.divisionList.length > 0) {
                this.info.divisionList.forEach(divItem => {
                  if (divItem.divisionProsonId == this.$store.state.userid || (this.info.teamLeaderId==this.$store.state.userid&&divItem.divisionIsSubmitted)) {
                    divItem.contentList.forEach(item => {
                      
                      this.list.push({
                        id: item.id,
                        checkResult: item.checkResult
                      })
                    })
                  }
                })
              }
            }
          }
        });
      },
    },
    beforeRouteEnter (to, from, next) {
      if (from.name == 'needCheck') {
        next(vm => vm.init())
      } else {
        next()
      }
    }
  }
</script>
<style lang="less" scoped>
#classValue2{
  .popList {
    height: 224px;
    li {
        height: 46px;
        border-bottom: 1px solid #f0f1f5;
        position: relative;
        background-color: #fff;
        p {
            width: 100%;
            height: 45px;
            line-height: 45px;
            position: absolute;
            left: 50%;
            top: 0;
            transform: translate(-50%, 0);
            font-size: 14px;
            margin-left: 12px;
            text-align: center;
           
            img {
                height: 14px;
                width: 14px;
                margin-left: 10px;
                vertical-align: middle;
                position: relative;
                top: -1px;
                opacity: 0;
            }
        }
    }
    li.active {
        p {
        color: #469b7a;
        }
        img {
        opacity: 1;
        }
    }
  }
  &.divClass {
      width: 100%;
      height: 300px;
      overflow-y: scroll;
      .hiddden {
            li.active {
            p {
            color: #469b7a;
            }
            img {
            opacity: 1;
            }
        }
          li {
              min-height: 46px;
              border-bottom: 1px solid #f0f1f5;
              position: relative;
              background-color: #fff;
              padding: 20px 0;
              p {
                  width: 90%;
                  box-sizing: border-box;
                  display: inline-block;
                  padding: 0 10px 0 20px;
              }
              img {
                  height: 14px;
                  width: 14px;
                  vertical-align: middle;
                  position: relative;
                  top: -10px;
                  opacity: 0;
              }
          }
      }
  }
}
input:disabled, input[disabled]{ color:#000000;-webkit-text-fill-color:#000000;}
  .active{
    display: none;
  }
  #aaa{
    background-color: #f4f4f4;
    ul{
      margin-top: -10px;
    }
    li{
      padding: 20px 10px;
      margin-bottom: 10px;
      line-height: 20px;
      background-color: #fff;
      overflow: hidden;
    }
    input{
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .el-checkbox{
      display: block;
      padding-top: 10px;
      margin-left: 20px;
      margin-bottom: 20px;
    }
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    .box{
      width: 100%;
      height: 100%;
      position: relative;
        .btns_div {
          justify-content: space-around;
          display: flex;
          margin-top: 20px;
          a {
            height: 20px;
            border-radius: 20px;
            display: inline-block;
            width: 70px;
            text-align: center;
            line-height: 20px;
            color: #fff;
          }
          .submitBtn {
            background: #469b7a;
          }
          .cancelBtn {
            background: #ffb400;
          }

      }
    }

  }
  .add_btn {
    position: fixed;
    background: url('../../assets/imgs/add_pro_icon.png') no-repeat;
    background-size: 62px;
    height: 62px;
    width: 62px;
    right: 30px;
    bottom: 35px;
    z-index: 1;
  }
  .transfer_p{
    padding: 10px 20px;
    height: 30px;
    span,em{
      width: 60px;
      height: 30px;
      text-align: center;
      line-height: 30px;
      font-size: 16px;
      border-radius: 5px;
      color: #fff;
    }
    span{
      float: left;
      background-color:#2abf72;
    }
    em{
      float: right;
      background-color: #ceaa6c;
    }
  }
  .member_div {
    .member_list {
      li {
        border-top: 5px solid #ebeef2;
      }

      .member1 {
        color: #ff0000;
      }

      .member2 {
        color: #15bd84;
      }
    }
  }
  .section-wrap{
    height: 100%;
  }
  .form-item {
    .input_div {
      .vux-x-icon {
        fill: #999;
        float: right;
        margin-top: 17px;
      }
    }
  }
  .info_div3 {
    height: 55px;
    line-height: 45px;
    padding: 0 20px;
    border-top: 10px solid #ebeef2;
    p {
      float: left;
      color: #469b7a;
      font-size: 16px;
      font-weight: bold;
      span{
        color: #999;
        font-weight: bold;
      }
    }
    .vux-x-icon {
      fill: #999;
      float: right;
      margin-top: 12px;
    }
  }
  .info_div4 {
    height: 60px;
    line-height: 50px;
    padding: 0 20px;
    border-top: 10px solid #ebeef2;
    p {
      float: left;
      color: #333;
      font-size: 16px;
      font-weight: bold;
    }
    .vux-x-icon {
      fill: #999;
      float: right;
      margin-top: 14px;
    }
  }

  .notice_div {
    border-top: 10px solid #ebeef2;
    padding-left: 20px;
    .notice_top {
      border-bottom: 1px solid #ebeef2;
      height: 45px;
      line-height: 44px;
      padding-right: 20px;
      p {
        float: left;
        color: #469b7a;
        font-size: 16px;
        font-weight: bold;
        span{
          color: #999;
          font-weight: bold;
        }
      }

      .vux-x-icon {
        fill: #999;
        float: right;
        margin-top: 12px;
      }
    }

    .notice_list {
      >li {
        .down_div{
          justify-content: space-between;
          border-bottom: 1px solid #ebeef2;
          height: 55px;
          padding-right: 20px;
          label {
            display: block;
            float: left;
            height: 54px;
            line-height: 54px;
            font-weight: bold;
          }

          .notice_item {
            float: right;
            .notice_number {
              background: #469b7a;
              color: #fff;
              height: 16px;
              width: 16px;
              border-radius: 50%;
              display: inline-block;
              text-align: center;
              line-height: 16px;
              font-size: 12px;
              margin-top: 19px;
            }

            .vux-x-icon {
              fill: #999;
              float: right;
              margin-top: 16px;
            }
          }
        }
        .cList{
          li{
            justify-content: space-between;
            border-bottom: 1px solid #ebeef2;
            align-items: center;
            display: flex;
            padding: 20px 13px 20px 0;
            font-size: 14px;
            p{
              float: left;
              width: calc(100% - 40px);
              line-height: 26px;
            }
            .vux-x-icon {
              fill: #999;
              float: right;
            }
          }
        }
      }

      li:last-child {
        border-bottom: none;
      }
    }
  }
  .btns_div {
    background: #ebeef2;
    padding: 30px 20px 55px;
    justify-content: center;
    display: flex;
    a {
      height: 40px;
      border-radius: 20px;
      display: inline-block;
      width: 140px;
      text-align: center;
      line-height: 40px;
      color: #fff;
    }

    .saveBtn {
      background: #469b7a;
      width: 45%;
    }

    .submitBtn {
      background: #469b7a;
      width: 70%;
    }
  }
  #safeDet .form-item-style1{
    line-height: normal;
  }
  .hiddenlc .vux-cell-box .weui-cell {
    padding-right: 0 !important;
    border: 0 !important;
  }
  .hiddenlc .vux-cell-box:not(:first-child):before {
    border: none !important;
  }
</style>
<style>
  .safeDetails .weui-textarea{
    height: 180px!important;
  }
</style>
